<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form
            inline
            size="small"
            :model="from"
            ref="from"
            :label-position="labelPosition"
            label-width="120px"
          >
            <el-row>
              <el-col :xs="24" :sm="24" :md="24" :lg="18" :xl="18">
                <el-form-item label="佣金模板名称：">
                  <el-input
                    v-model="from.brokerageTemplateName"
                    placeholder="请输入佣金模板名称"
                    clearable
                    class="selWidth"
                  />
                </el-form-item>
                <el-form-item label="佣金模板编号：">
                  <el-input
                    v-model="from.brokerageTemplateNo"
                    placeholder="请输入佣金模板编号"
                    clearable
                    class="selWidth"
                  />
                </el-form-item>

                <el-form-item label="是否默认模板：">
                  <el-select
                    v-model="from.isDefault"
                    placeholder="请选择"
                    class="selWidth"
                    clearable
                  >
                    <el-option :value="1" label="是"></el-option>
                    <el-option :value="2" label="否"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="状态：">
                  <el-select
                    v-model="from.status"
                    placeholder="请选择"
                    class="selWidth"
                    clearable
                  >
                    <el-option :value="1" label="正常"></el-option>
                    <el-option :value="2" label="禁用"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col
                :xs="24"
                :sm="24"
                :md="24"
                :lg="6"
                :xl="6"
                class="text-right from"
              >
                <el-form-item>
                  <el-button
                    class="mr10"
                    size="small"
                    type="primary"
                    icon="el-icon-search"
                    @click="search()"
                    >搜索</el-button
                  >
                  <el-button class="mr10" icon="el-icon-refresh" size="small" @click="reset()"
                    >重置</el-button
                  >
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div class="btn_bt">
          <el-button class="mr10" icon="el-icon-circle-plus-outline" size="small" type="primary" @click="add()"
            >新增</el-button
          >
          <el-button class="mr10" icon="el-icon-delete" size="small" type="danger" @click="allDel()"
            >删除</el-button
          >
          <el-button class="mr10" icon="el-icon-top" size="small" @click="exportTable()"
            >导出表格</el-button
          >
        </div>
      </div>
      <el-table
        border
        ref="table"
        v-loading="loading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        @selection-change="onSelectTab"
        highlight-current-row
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="id" label="ID" min-width="80" />
        <el-table-column
          prop="brokerageTemplateName"
          label="佣金模板名称"
          min-width="100"
        />
        <el-table-column
          prop="brokerageTemplateNo"
          label="佣金模板编号"
          min-width="100"
        />
        <el-table-column prop="operationCost" label="运营成本" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.operationCost * 100 || 0 }}%
          </template>
        </el-table-column>
        <el-table-column prop="isDefault" label="是否默认模板" min-width="100">
          <template slot-scope="scope">
            <el-button size="mini" v-if="scope.row.isDefault == 1"
              >是</el-button
            >
            <el-button size="mini" v-if="scope.row.isDefault == 2"
              >否</el-button
            >
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" min-width="80">
          <template slot-scope="scope">
            <el-button size="mini" v-if="scope.row.status == 1">正常</el-button>
            <el-button size="mini" v-if="scope.row.status == 2">禁用</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" min-width="100" />
        <el-table-column
          label="操作"
          min-width="130"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleDetails(scope.row)"
              >详情</el-button
            >
            <el-button type="text" size="small" @click="handleEdit(scope.row)"
              >编辑</el-button
            >
            <el-button type="text" size="small" @click="handleDel(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[15, 30, 45, 60]"
          :page-size="from.limit"
          :current-page="from.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>

    <el-dialog :visible.sync="visible" :fullscreen="true">
      <el-form v-for="(item, index) in dtlList" :key="index" :model="item">
        <el-divider>{{ item.dictLabel }}</el-divider>
        <el-form-item label="平级奖励是否启用：">
          <el-radio-group v-model="item.parallelRewardIsEnable">
            <el-radio disabled :label="1">启用</el-radio>
            <el-radio disabled :label="2">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="平级奖励：">
          <el-input disabled v-model="item.parallelReward"></el-input>
        </el-form-item>
        <el-form-item label="佣金类型：">
          <el-radio-group v-model="item.brokerageType">
            <el-radio disabled :label="1">阶梯佣金</el-radio>
            <el-radio disabled :label="2">固定佣金</el-radio>
            <el-radio disabled :label="3">百分比</el-radio>
            <!-- 新增 -->
            <el-radio disabled :label="4">阶梯比率</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="佣金设置：">
          <el-table border :data="item.brokerageDetailList" style="width: 100%">
            <el-table-column
              label="最小次数"
              width="150"
              v-if="item.brokerageType == 1"
            >
              <template slot-scope="scope">
                <el-input disabled v-model="scope.row.countMin"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              label="最大次数"
              width="150"
              v-if="item.brokerageType == 1"
            >
              <template slot-scope="scope">
                <el-input disabled v-model="scope.row.countMax"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="品种设置" v-if="item.brokerageType != 3">
              <template slot-scope="scope">
                <div
                  style="
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    width: 100%;
                    overflow-x: auto;
                  "
                >
                  <div
                    v-for="(items, indexs) in scope.row.exchangeCommodityVoList"
                    :key="indexs"
                    style="
                      display: flex;
                      justify-content: center;
                      align-items: center;
                      margin-right: 30px;
                    "
                  >
                    <div style="width: 80px">
                      {{ items.commodityName }}佣金:
                    </div>
                    <el-input
                      style="width: 200px; margin-left: 10px"
                      disabled
                      v-model="items.commodityFee"
                    ></el-input>
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <el-input
            v-if="item.brokerageType === 3"
            :value="`占百分比 ${item.percentReward} %`"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="备注：" style="margin-top: 20px">
          <el-input type="textarea" disabled v-model="item.remark"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      :title="ruleForm.id ? '编辑' : '新增'"
      :visible.sync="dialogVisible"
      :fullscreen="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form
        :rules="rules"
        ref="ruleForm"
        :model="ruleForm"
        label-width="120px"
      >
        <el-form-item label="佣金模板名称：" prop="brokerageTemplateName">
          <el-input v-model="ruleForm.brokerageTemplateName"></el-input>
        </el-form-item>
        <el-form-item label="佣金模板编号：" prop="brokerageTemplateNo">
          <el-input v-model="ruleForm.brokerageTemplateNo"></el-input>
        </el-form-item>
        <el-form-item label="运营成本：" prop="operationCost">
          <el-input-number
            v-model="ruleForm.operationCost"
            :min="0"
            :max="99"
          ></el-input-number
          >%
        </el-form-item>
        <el-form-item
          v-for="(item, index) in ruleForm.dtlList"
          :key="index"
          :label="item.dictLabel + '：'"
          prop="dtlList"
        >
          <el-form :model="item" label-width="150px">
            <el-form-item label="平级奖励是否启用：">
              <el-radio-group v-model="item.parallelRewardIsEnable">
                <el-radio :label="1">启用</el-radio>
                <el-radio :label="2">关闭</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="平级奖励：">
              <el-input v-model="item.parallelReward"></el-input>
            </el-form-item>
            <el-form-item label="佣金类型：">
              <el-radio-group
                v-model="item.brokerageType"
                @change="handleChange(item)"
              >
                <el-radio :label="1">阶梯佣金</el-radio>
                <el-radio :label="2">固定佣金</el-radio>
                <el-radio :label="3">百分比</el-radio>
                <!-- 新增 -->
                <el-radio :label="4">阶梯比率</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="佣金设置：">
              <el-table
                :data="item.brokerageDetailList"
                v-if="item.brokerageType == 1"
                border
                style="width: 100%"
              >
                <el-table-column label="最小次数" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.countMin"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="最大次数" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.countMax"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="品种设置">
                  <template slot-scope="scope">
                    <div>
                      <div
                        style="
                          display: flex;
                          justify-content: flex-start;
                          align-items: center;
                          width: 100%;
                          overflow-x: auto;
                        "
                      >
                        <div
                          v-for="(items, indexs) in scope.row
                            .exchangeCommodityVoList"
                          :key="indexs"
                          style="
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            margin-right: 30px;
                          "
                        >
                          <div style="width: 80px">
                            {{ items.commodityName }}佣金:
                          </div>
                          <el-input
                            style="width: 200px; margin-left: 10px"
                            v-model="items.commodityFee"
                          ></el-input>
                        </div>
                      </div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="160">
                  <template slot-scope="scope">
                    <el-button
                      class="mr"
                      size="mini"
                      type="danger"
                      @click="holidaysDel(item, scope.$index, scope.row)"
                      >删除
                    </el-button>
                    <el-button
                      v-if="scope.$index == 0 && item.brokerageType == 1"
                      class="mr"
                      size="mini"
                      type="success"
                      @click="holidaysAdd(item, scope.$index, scope.row)"
                      >添加
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <el-table
                border
                :data="[item.brokerageDetailList[0]]"
                v-if="item.brokerageType == 2"
                style="width: 100%"
              >
                <el-table-column label="品种设置">
                  <template slot-scope="scope">
                    <div>
                      <div
                        style="
                          display: flex;
                          justify-content: flex-start;
                          align-items: center;
                          width: 100%;
                          overflow-x: auto;
                        "
                      >
                        <div
                          v-for="(items, indexs) in scope.row
                            .exchangeCommodityVoList"
                          :key="indexs"
                          style="
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            margin-right: 30px;
                          "
                        >
                          <div style="width: 80px">
                            {{ items.commodityName }}佣金:
                          </div>
                          <el-input
                            style="width: 200px; margin-left: 10px"
                            v-model="items.commodityFee"
                          ></el-input>
                        </div>
                      </div>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
              <el-table
                :data="item.brokerageDetailList"
                v-if="item.brokerageType == 3"
                border
                style="width: 100%"
              >
                <el-table-column label="请设置百分比（单位：%）">
                  <template>
                    <el-input-number
                      v-model="item.percentReward"
                      :step="1"
                      :min="0"
                      :max="100"
                    >
                    </el-input-number
                    >%
                  </template>
                </el-table-column>
              </el-table>

              <el-table
                :data="item.brokerageDetailList"
                v-if="item.brokerageType == 4"
                border
                style="width: 100%"
              >
                <el-table-column label="最小次数" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.countMin"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="最大次数" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.countMax"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="请设置百分比（单位：%）">
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.percentReward"
                      :step="1"
                      :min="0"
                      :max="100"
                    >
                    </el-input-number
                    >%
                  </template>
                </el-table-column>

                <el-table-column label="操作" width="160">
                  <template slot-scope="scope">
                    <el-button
                      class="mr"
                      size="mini"
                      type="danger"
                      @click="holidaysDel2(item, scope.$index, scope.row)"
                      >删除
                    </el-button>
                    <el-button
                      v-if="scope.$index == 0 && item.brokerageType == 4"
                      class="mr"
                      size="mini"
                      type="success"
                      @click="holidaysAdd2(item, scope.$index, scope.row)"
                      >添加
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
            <el-form-item label="备注：" style="margin-top: 20px">
              <el-input type="textarea" v-model="item.remark"></el-input>
            </el-form-item>
          </el-form>
        </el-form-item>
        <el-form-item label="是否默认模板：">
          <el-radio-group v-model="ruleForm.isDefault">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="状态：">
          <el-radio-group v-model="ruleForm.status">
            <el-radio :label="1">正常</el-radio>
            <el-radio :label="2">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注：">
          <el-input type="textarea" v-model="ruleForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close()">取 消</el-button>
        <el-button type="primary" @click="submit()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { exchangecommodityGetOption } from "@/api/transaction";
import {
  yj_brokerage_member_type,
  brokeragetemplateList,
  brokeragetemplateSave,
  brokeragetemplateInfo,
  brokeragetemplateUpdate,
  brokeragetemplateDelete,
  brokeragetemplateExport,
} from "@/api/agent";
export default {
  name: "brokeragetemplate",
  data() {
    return {
      labelPosition: "right",
      from: {
        brokerageTemplateName: "",
        brokerageTemplateNo: "",
        isDefault: "",
        status: 1,
        page: 1,
        limit: 15,
      },
      loading: false,
      tableData: {
        data: [],
        total: 0,
      },
      selection: [],
      dialogVisible: false,
      visible: false,
      dtlList: [],
      ruleForm: {
        id: "",
        brokerageTemplateName: "",
        brokerageTemplateNo: "",
        dtlList: [],
        isDefault: "",
        status: 1,
        remark: "",
      },
      rules: {
        brokerageTemplateName: [
          {
            required: true,
            message: "请填写佣金模板名称",
            trigger: "blur",
          },
        ],
        brokerageTemplateNo: [
          {
            required: true,
            message: "请填写佣金模板编号",
            trigger: "blur",
          },
        ],
      },
    };
  },
  mounted() {
    this.getlist();
  },
  methods: {
    search() {
      console.log(this.from);
      this.from.page = 1;
      this.from.limit = 15;
      this.getlist();
    },
    reset() {
      this.from = {
        brokerageTemplateName: "",
        brokerageTemplateNo: "",
        isDefault: "",
        status: 1,
        page: 1,
        limit: 15,
      };
      this.getlist();
    },
    getlist() {
      this.loading = true;
      brokeragetemplateList(this.from)
        .then((res) => {
          console.log(res);
          this.tableData.data = res.list;
          this.tableData.data = res.list;
          this.tableData.total = res.total;
          this.loading = false;
        })
        .catch((err) => {
          console.log(err);
          this.loading = false;
        });
    },
    add() {
      this.ruleForm = {
        id: "",
        brokerageTemplateName: "",
        brokerageTemplateNo: "",
        dtlList: [],
        isDefault: "",
        status: 1,
        remark: "",
        operationCost: 0,
      };
      yj_brokerage_member_type()
        .then((res) => {
          console.log("佣金模板添加级别列表", res);
          res.forEach((item) => {
            this.ruleForm.dtlList.push({
              memberType: item.dictValue,
              dictLabel: item.dictLabel,
              parallelRewardIsEnable: "",
              parallelReward: "",
              percentReward: 0,
              remark: "",
              brokerageType: "",
              brokerageDetailList: [
                {
                  countMax: "",
                  countMin: "",
                  exchangeCommodityVoList: [],
                },
              ],
            });
          });
          exchangecommodityGetOption()
            .then((res) => {
              console.log("品种全列表", this.ruleForm, res);
              res.forEach((items) => {
                this.ruleForm.dtlList.forEach((item) => {
                  item.brokerageDetailList[0].exchangeCommodityVoList.push({
                    id: items.id,
                    commodityName: items.commodityName,
                    commodityFee: "",
                  });
                });
              });
              console.log(this.ruleForm);
              this.dialogVisible = true;
            })
            .catch((err) => {
              console.log(err);
            });
        })
        .catch((err) => {
          console.log(err);
        });
    },
    close() {
      this.ruleForm = {
        id: "",
        brokerageTemplateName: "",
        brokerageTemplateNo: "",
        dtlList: [],
        isDefault: "",
        status: 1,
        remark: "",
        operationCost: 0,
      };
      this.dialogVisible = false;
    },
    handleChange(item) {
      console.log("单选选择数据处理", item);
      if (item.brokerageType == 2 || item.brokerageType == 3) {
        item.brokerageDetailList = JSON.parse(
          JSON.stringify(item.brokerageDetailList.slice(0, 1))
        );
      }

      // 新加代码,切换只拿一条数据
      if (item.brokerageType == 1 || item.brokerageType == 4) {
        item.brokerageDetailList = JSON.parse(
          JSON.stringify(item.brokerageDetailList.slice(0, 1))
        );
      }
    },
    holidaysDel(item, index, row) {
      this.ruleForm.dtlList.forEach((items) => {
        if (items.dictLabel == item.dictLabel) {
          if (items.brokerageDetailList.length > 1) {
            items.brokerageDetailList.splice(index, 1);
          } else {
            this.$message.error("不能继续删除");
          }
        }
      });
    },
    holidaysAdd(item, index, row) {
      this.ruleForm.dtlList.forEach((items) => {
        if (items.dictLabel == item.dictLabel) {
          exchangecommodityGetOption()
            .then((res) => {
              let exchangeCommodityVoList = [];
              res.forEach((i) => {
                exchangeCommodityVoList.push({
                  id: i.id,
                  commodityName: i.commodityName,
                  commodityFee: "",
                });
              });
              items.brokerageDetailList.push({
                countMax: "",
                countMin: "",
                exchangeCommodityVoList: exchangeCommodityVoList,
              });
            })
            .catch((err) => {
              console.log(err);
            });
        }
      });
    },
    // 新增阶梯比率
    holidaysDel2(item, index, row) {
      this.ruleForm.dtlList.forEach((items) => {
        if (items.dictLabel == item.dictLabel) {
          if (items.brokerageDetailList.length > 1) {
            items.brokerageDetailList.splice(index, 1);
          } else {
            this.$message.error("不能继续删除");
          }
        }
      });
    },
    holidaysAdd2(item, index, row) {
      this.ruleForm.dtlList.forEach((items) => {
        if (items.dictLabel == item.dictLabel) {
          exchangecommodityGetOption()
            .then((res) => {
              items.brokerageDetailList.push({
                countMax: "",
                countMin: "",
                percentReward: "",
              });
            })
            .catch((err) => {
              console.log(err);
            });
        }
      });
    },

    submit() {
      this.ruleForm.dtlList.forEach((v) => {
        if (v.percentReward)
          v.percentReward = (v.percentReward / 100).toFixed(2);
      });
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          for (var i = 0; i < this.ruleForm.dtlList.length; i++) {
            if (
              this.ruleForm.dtlList[i].brokerageType == 2 ||
              this.ruleForm.dtlList[i].brokerageType == 3
            ) {
              this.ruleForm.dtlList[i].brokerageDetailList =
                this.ruleForm.dtlList[i].brokerageDetailList.slice(0, 1);
            }
            if (
              this.ruleForm.dtlList[i].brokerageType == 2 &&
              this.ruleForm.dtlList[i].brokerageDetailList.length > 1
            ) {
              return this.$message.error(
                this.ruleForm.dtlList[i].dictLabel +
                  ":佣金类型使用固定佣金，佣金设置必须为一条数据"
              );
            }
          }
          if (this.ruleForm.id) {
            console.log("编辑", this.ruleForm);
            (this.ruleForm.operationCost =
              (this.ruleForm.operationCost / 100).toFixed(2) || 0),
              brokeragetemplateUpdate(this.ruleForm)
                .then((res) => {
                  console.log(res);
                  this.close();
                  this.$message.success("编辑成功");
                  this.getlist();
                })
                .catch((err) => {
                  console.log(err);
                  this.$message.error(err);
                });
          } else {
            console.log("新增", this.ruleForm);
            let data = {
              brokerageTemplateName: this.ruleForm.brokerageTemplateName,
              brokerageTemplateNo: this.ruleForm.brokerageTemplateNo,
              operationCost: this.ruleForm.operationCost,
              dtlList: this.ruleForm.dtlList,
              isDefault: this.ruleForm.isDefault,
              status: this.ruleForm.status,
              remark: this.ruleForm.remark,
              operationCost: this.ruleForm.operationCost
                ? (this.ruleForm.operationCost / 100).toFixed(2)
                : 0,
            };
            brokeragetemplateSave(data)
              .then((res) => {
                console.log(res);
                this.close();
                this.$message.success("新增成功");
                this.getlist();
              })
              .catch((err) => {
                console.log(err);
                this.$message.error(err);
              });
          }
        } else {
          this.$message.error("请填写完整信息");
        }
      });
    },
    // 选择
    onSelectTab(selection) {
      this.selection = [];
      selection.forEach((item) => {
        this.selection.push(item.id);
      });
      console.log(this.selection);
    },
    allDel() {
      if (this.selection.length == 0) {
        return this.$message.error("至少选择一项");
      }
      console.log(this.selection);
      this.$confirm("确认删除？")
        .then((_) => {
          brokeragetemplateDelete(this.selection)
            .then((res) => {
              console.log(res);
              this.$message.success("删除成功");
              this.getlist();
            })
            .catch((err) => {
              console.log(err);
              this.$message.error(err);
            });
        })
        .catch((_) => {});
    },
    exportTable() {
      brokeragetemplateExport(this.from)
        .then((res) => {
          console.log("导出表格", res);
          window.open(res.filename);
        })
        .catch((err) => {
          console.log(err);
          this.$message.error(err);
        });
    },
    handleDetails(row) {
      brokeragetemplateInfo(row.id)
        .then((res) => {
          console.log("详情", res);
          this.dtlList = res.dtlList;
          this.dtlList.forEach((v) => {
            v.percentReward = Math.trunc(v.percentReward * 100);
          });
          this.visible = true;
        })
        .catch((err) => {
          console.log(err);
          this.$message.error(err);
        });
    },
    handleEdit(row) {
      console.log("编辑", row);
      brokeragetemplateInfo(row.id)
        .then((res) => {
          console.log("详情", res);
          this.ruleForm = {
            id: res.id,
            brokerageTemplateName: res.brokerageTemplateName,
            brokerageTemplateNo: res.brokerageTemplateNo,
            operationCost: res.operationCost * 100 || 0,
            dtlList: res.dtlList,
            isDefault: Number(res.isDefault),
            status: Number(res.status),
            remark: res.remark,
          };
          this.ruleForm.dtlList.forEach((v) => {
            v.percentReward = Math.trunc(v.percentReward * 100);
          });
          this.dialogVisible = true;
        })
        .catch((err) => {
          console.log(err);
          this.$message.error(err);
        });
    },
    handleDel(row) {
      this.$confirm("确认删除？")
        .then((_) => {
          console.log("删除", row);
          brokeragetemplateDelete([row.id])
            .then((res) => {
              console.log(res);
              this.$message.success("删除成功");
              this.getlist();
            })
            .catch((err) => {
              console.log(err);
              this.$message.error(err);
            });
        })
        .catch((_) => {});
    },
    pageChange(page) {
      this.from.page = page;
      this.getlist();
    },
    handleSizeChange(val) {
      this.from.limit = val;
      this.getlist();
    },
  },
};
</script>

<style scoped lang="scss">
.btn_bt {
  border-top: 1px dashed #ccc;
  padding-top: 20px;
}
</style>
